package com.potenza.training.interview.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.potenza.training.interview.dao.InterviewInvitationDao;
import com.potenza.training.interview.entity.InterviewInvitationEntity;
import com.potenza.training.interview.service.InterviewInvitationService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Map;


@Service("interviewInvitationService")
public class InterviewInvitationServiceImpl extends ServiceImpl<InterviewInvitationDao, InterviewInvitationEntity> implements InterviewInvitationService {

    @Autowired
    InterviewInvitationDao interviewInvitationDao;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<InterviewInvitationEntity> interviewInvitationEntityQueryWrapper = new QueryWrapper<>();
        String key = (String) params.get("key");
        if (!StringUtils.isEmpty(key)){
            interviewInvitationEntityQueryWrapper.lambda().like(InterviewInvitationEntity::getInterviewCompany,key);
        }
        IPage<InterviewInvitationEntity> page = this.page(
                new Query<InterviewInvitationEntity>().getPage(params),
                interviewInvitationEntityQueryWrapper
        );
        page.setTotal(new Long(interviewInvitationDao.selectList(interviewInvitationEntityQueryWrapper).size()));
        return new PageUtils(page);
    }

    @Override
    public List<InterviewInvitationEntity> findAll() {
        return baseMapper.selectList(null);
    }

}